package cn.jdy.anquan.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jdy.anquan.entity.Report;
import cn.jdy.anquan.service.ReportService;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.DateUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 【中小企业服务平台】-【我要举报】控制类
 * 
 * @author luzhirui
 */
@Controller
@RequestMapping("/report")
public class ReportCtrl extends BaseCtrl {

  @Autowired
  private ReportService reportService;
  
  /**
   * 我要举报页面
   */
  @RequestMapping("")
  public ModelAndView index(String type) {
    ModelAndView mv = new ModelAndView("/report/report.jsp");
    Map<String, Object> reasonMap = new HashMap<String, Object>();
    

    if (type==null || "website".equals(type)) {
      type = "website";
      mv.addObject("typeName", "网址");
      mv.addObject("marginLeft", "45px");
      
      
      reasonMap.put("1", "欺诈类");
      reasonMap.put("2", "假冒类");
      reasonMap.put("3", "违法违规类");

      Map<String, Object> sonReasonMap1 = new HashMap<String, Object>();
      sonReasonMap1.put("1", "中奖诈骗");
      sonReasonMap1.put("2", "彩票预测");
      sonReasonMap1.put("3", "虚假购物");
      sonReasonMap1.put("4", "虚假交易");
      sonReasonMap1.put("5", "虚假票务");
      sonReasonMap1.put("6", "假药");
      sonReasonMap1.put("7", "虚假医疗");
      sonReasonMap1.put("8", "虚假游戏");
      sonReasonMap1.put("9", "其他欺诈网站");

      Map<String, Object> sonReasonMap2 = new HashMap<String, Object>();
      sonReasonMap2.put("1", "假冒伪劣商品");
      sonReasonMap2.put("2", "钓鱼网站");
      sonReasonMap2.put("3", "账号窃取");
      sonReasonMap2.put("4", "假办信用卡");
      sonReasonMap2.put("5", "其他假冒网站");

      Map<String, Object> sonReasonMap3 = new HashMap<String, Object>();
      sonReasonMap3.put("1", "博彩赌球");
      sonReasonMap3.put("2", "黑心食品");
      sonReasonMap3.put("3", "淫秽色情");
      sonReasonMap3.put("4", "虚假广告");
      sonReasonMap3.put("5", "木马病毒");
      sonReasonMap3.put("6", "其他违法违规");

      mv.addObject("sonReason1", sonReasonMap1);
      mv.addObject("sonReason2", sonReasonMap2);
      mv.addObject("sonReason3", sonReasonMap3);

    } else if ("phone".equals(type)) {
      mv.addObject("typeName", "电话号码");
      mv.addObject("marginLeft", "22px");
      
      reasonMap.put("1", "欺诈电话");
      reasonMap.put("2", "骚扰电话");
      reasonMap.put("3", "欺骗短信");
      reasonMap.put("4", "垃圾短信");
      reasonMap.put("5", "非法业务");
      reasonMap.put("6", "中介");
      reasonMap.put("7", "商业广告");
      reasonMap.put("8", "政治敏感言论");
      reasonMap.put("9", "其他类型");
    } else if ("qq".equals(type)) {
      mv.addObject("typeName", "QQ号码");
      mv.addObject("marginLeft", "25px");
      
      reasonMap.put("1", "淫秽色情");
      reasonMap.put("2", "广告欺骗");
      reasonMap.put("3", "冒充好友骗钱");
      reasonMap.put("4", "恶意骚扰");
      reasonMap.put("5", "政治敏感言论");
      reasonMap.put("6", "其他类型");
    } else if ("wechat".equals(type)) {
      mv.addObject("typeName", "微信号码");
      mv.addObject("marginLeft", "22px");
      
      reasonMap.put("1", "发布虚假信息");
      reasonMap.put("2", "淫秽色情");
      reasonMap.put("3", "骚扰/垃圾广告");
      reasonMap.put("4", "强制其他用户关注");
      reasonMap.put("5", "政治敏感言论");
      reasonMap.put("6", "侵犯第三方合法权益");
      reasonMap.put("7", "其他类型");
    } else if ("tencentweibo".equals(type)) {
      mv.addObject("typeName", "腾讯微博地址");
      mv.addObject("marginLeft", "0px");
      
      reasonMap.put("1", "淫秽色情");
      reasonMap.put("2", "广告欺诈");
      reasonMap.put("3", "反动政治");
      reasonMap.put("4", "谩骂骚扰");
      reasonMap.put("5", "伪造他人言论");
      reasonMap.put("6", "机器人");
      reasonMap.put("7", "恶意@");
      reasonMap.put("8", "其他类型");
    } else if ("sinaweibo".equals(type)) {
      mv.addObject("typeName", "新浪微博地址");
      mv.addObject("marginLeft", "0px");
      
      reasonMap.put("1", "虚假中奖");
      reasonMap.put("2", "垃圾广告");
      reasonMap.put("3", "不实信息");
      reasonMap.put("4", "敏感信息");
      reasonMap.put("5", "淫秽色情");
      reasonMap.put("6", "人身攻击我");
      reasonMap.put("7", "骚扰我");
      reasonMap.put("8", "冒充我");
      reasonMap.put("9", "抄袭我的内容");
      reasonMap.put("10", "泄露我的隐私");
      reasonMap.put("11", "其他类型");
    } else if ("taobao".equals(type)) {
      mv.addObject("typeName", "淘宝店地址");
      mv.addObject("marginLeft", "10px");
      
      reasonMap.put("1", "假货");
      reasonMap.put("2", "质量差");
      reasonMap.put("3", "欺诈");
      reasonMap.put("4", "服务差");
      reasonMap.put("5", "强制好评");
      reasonMap.put("6", "发货慢");
      reasonMap.put("7", "商品与描述不符");
      reasonMap.put("8", "卖家恶意骚扰");
      reasonMap.put("9", "其他类型");
    }

    mv.addObject("reason", reasonMap);
    mv.addObject("type", type);

    return mv;
  }
  
  /**
   * 曝光台
   */
  @RequestMapping(value = "/exposed")
  public ModelAndView exposed(Report bo, Integer pageNo,Integer pageSize,Integer type) {
    List<Report> list = null;
    if(pageNo==null) pageNo = 1;
    System.out.println(pageSize);
    if(pageSize==null)pageSize = 10;
    System.out.println(pageSize);
    int count = 0;
    ModelAndView mv = new ModelAndView("/report/exposed.jsp");
    int reason = 0;
    if (type==null) {
      type = 0;
    }
    reason = type;
    bo.setReason(reason);
    bo.setiDisplayStart((pageNo - 1) * pageSize);//查询起始值
    bo.setiDisplayLength(pageSize);//查询条数
    
    count = reportService.getCount(bo);
    list = reportService.query(bo);
    
    mv.addObject("type", type);
    mv.addObject("pageNo", bo.getPageNo());
    mv.addObject("size", pageSize);
    mv.addObject("total", count);
    mv.addObject("reportlist", list);
    
    return mv;
  }
  
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  @ResponseBody
  public Map<String, Object> saveWebsite(Report report){
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    try {
	  report.setCreateTime(DateUtil.getCurrentDate2());
      report.setStatus(0);
      reportService.save(report);
      jsonMap.put("status", 200);
    } catch (Exception e) {
      jsonMap.put("status", 500);
      BaseLog.e(this.getClass(), "保存举报信息失败", e);
    }
    return jsonMap;
  }

}